// 题目链接：https://www.luogu.com.cn/problem/P1162

#include <iostream>
#include <cstring>
#include <queue>
using namespace std;

#define x first
#define y second

typedef pair<int, int> PII;

const int N = 35;
int g[N][N];
bool st[N][N];
queue<PII> q;

int n;
int dx[] = {-1, 0, 0, 1};
int dy[] = {0, -1, 1, 0};

void BFS()
{
    q.push({0, 0});

    while (!q.empty())
    {
        auto t = q.front();
        q.pop();

        for (int i = 0; i < 4; ++i)
        {
            int next_x = t.x + dx[i];
            int next_y = t.y + dy[i];

            if (next_x < 0 || next_x > n + 1 || next_y < 0 || next_y > n + 1)
                continue;
            if (g[next_x][next_y] != 0)
                continue;
            if (st[next_x][next_y])
                continue;

            q.push({next_x, next_y});
            st[next_x][next_y] = true;
        }
    }
}

int main()
{
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i)
    {
        for (int j = 1; j <= n; ++j)
        {
            scanf("%d", &g[i][j]);
        }
    }

    BFS();

    for (int i = 1; i <= n; ++i)
    {
        for (int j = 1; j <= n; ++j)
        {
            if (!st[i][j] && g[i][j] == 0)
                printf("%d ", 2);
            else
                printf("%d ", g[i][j]);
        }
        printf("\n");
    }

    return 0;
}